home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / dwmx61.exe / Disk1 / data1.cab / Configuration_En / Inspectors / meta.js < prev    next >
Encoding:
JavaScript  |  2002-11-25  |  3.3 KB  |  107 lines

  1. // Copyright 2000-2002 Macromedia, Inc. All rights reserved.
  2. //form field names:
  3. //metaAttribute - drop down menu - name is [0] and http is [1]
  4. //metaValue - text field
  5. //metaContent - text field
  6.  
  7. // *********** GLOBAL VARS *****************************
  8.  
  9. var helpDoc = MM.HELP_inspMeta;
  10.  
  11. // ******************** API ****************************
  12. function canInspectSelection(){
  13.   var dom = dw.getDocumentDOM();
  14.   var metaObj = dom.getSelectedNode();
  15.   return (metaObj.tagName && metaObj.tagName=="META");
  16. }
  17.  
  18. function inspectSelection(){
  19.   var dom = dw.getDocumentDOM();
  20.   var metaObj = dom.getSelectedNode();
  21.  
  22.   if (String(metaObj.tagName) == "undefined") return;
  23.   
  24.   var metaValue = findObject("metaValue");
  25.   var metaAttribute = findObject("metaAttribute");
  26.   var metaContent = findObject("metaContent");
  27.   var metaImage = findObject("metaImage");
  28.   
  29.   var useNameAttr = metaObj.getAttribute("name") != null && metaObj.getAttribute("name") != undefined;
  30.   var thisContent = metaObj.getAttribute("content");
  31.   // Convert any returns in the Content to spaces before populating field.
  32.   // If this replacement results in double spaces, convert to 
  33.   // single spaces.
  34.   // (This is just to be doubly-safe; we already strip returns when the
  35.   // user inserts a Meta tag from the Insert bar.)
  36.   if (thisContent && thisContent != undefined){
  37.     thisContent = thisContent.replace(/[\n\r]/g," ");
  38.     thisContent = thisContent.replace(/\s+/g, " ");
  39.   }
  40.  
  41.   var thisAttribute;
  42.   
  43.  
  44.  //fill in PI
  45.   if (useNameAttr){
  46.     metaAttribute.selectedIndex = 0;
  47.   }else{
  48.     metaAttribute.selectedIndex = 1;
  49.   }
  50.   
  51.   if (useNameAttr){
  52.     thisAttribute = metaObj.getAttribute("name");
  53.       metaImage.src="name.gif";
  54.   }
  55.   else{
  56.     if (metaObj.getAttribute("http-equiv") != undefined){
  57.       thisAttribute = metaObj.getAttribute("http-equiv");
  58.     }else{
  59.       thisAttribute = "";
  60.     }
  61.       metaImage.src="http.gif";
  62.   }    
  63.     
  64.   //fill in attribute value if present, otherwise fill text field with empty string    
  65.   metaValue.value = thisAttribute;    
  66.   //fill in meta content if present, otherwise fill text field with empty string
  67.   metaContent.value = (thisContent != undefined && thisContent != null)?thisContent:"";
  68.   showHideTranslated();    
  69. }
  70.  
  71.  
  72.  
  73.  
  74. // ******************** LOCAL FUNCTIONS ****************************
  75.  
  76. function setMetaTag(){
  77.   var dom = dw.getDocumentDOM();
  78.   var metaObj = dom.getSelectedNode();
  79.  
  80.   var metaValue = findObject("metaValue").value;
  81.   var metaAttribute = findObject("metaAttribute");
  82.   var metaContent = findObject("metaContent");
  83.   var metaImage = findObject("metaImage");
  84.  
  85.   if (metaAttribute.selectedIndex == 0){
  86.     metaObj.removeAttribute("http-equiv");
  87.     metaObj.setAttribute("name",metaValue);
  88.   } else {
  89.     metaObj.removeAttribute("name");
  90.     metaObj.setAttribute("http-equiv",metaValue);
  91.   }
  92.    //attribute is removed and then re-applied so that content attribute
  93.    //always appears after name and http-equiv attributes
  94.    metaObj.removeAttribute("content"); 
  95.    metaObj.setAttribute("content",metaContent.value);
  96.  
  97.    // set to http-equiv  
  98.    if (metaAttribute.selectedIndex == 1 && metaValue.toLowerCase() ==  "content-type"){
  99.        dom.setCharSet(metaContent.value);  // this causes dreamweaver to recognize the changes to the encoding and update the fonts in the code view
  100.     } 
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.